# 模型评估

import paddle
from paddleseg.core import evaluate
from paddleseg.models import DeepLabV3
from paddleseg.models.backbones import ResNet18_vd, ResNet34_vd, ResNet50_vd, ResNet101_vd, ResNet152_vd
from src.config.config import NUM_CLASSES, MODEL_PATH
from src.util.dataset import test_dataset

model = DeepLabV3(
    num_classes=NUM_CLASSES,
    backbone=ResNet50_vd(),  # currently support Resnet50_vd/Resnet101_vd/Xception65.
    pretrained=None
)

# 设置模型参数
if MODEL_PATH:
    para_state_dict = paddle.load(MODEL_PATH)
    model.set_dict(para_state_dict)
    print('Loaded trained params of model successfully')
else:
    raise ValueError('The model_path is wrong: {}'.format(MODEL_PATH))

# 评估测试集
evaluate(model, test_dataset)

# ```
# 由上可知测试集评估结果如下：
# ```
#
# ###### 总体数据
#
# | Images | mIoU | Acc | Kappa | Dice |
# | -------- | -------- | -------- |-------- | -------- |
# | 665     | 0.5931     | 0.8185     | 0.7626     | 0.7305     |
#
#
# ###### 每一类数据
#
# | Class| 未知 | 裸地| 草地| 构筑物 | 道路| 林地| 水域| 耕地 | 房屋|
# | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
# | Class label | 0     | 1     | 2     | 3     | 4     | 5     | 6     | 7     | 8     |
# | Class IoU     | 0.5812| 0.373| 0.5463| 0.2988|  0.6272|  0.8699|  0.7247|  0.6914|  0.6256|
# | Class Precision|  0.8196 | 0.4734 | 0.6953 | 0.5994 | 0.791  | 0.9095 | 0.8701 | 0.8347 | 0.7112|
# | Class Recall|  0.6665 | 0.6377|  0.7183 | 0.3734|  0.7517|  0.9523|  0.8127|  0.801 |  0.8387|
#
#
